<template>
  <div class="login-container">
    <h2>Login</h2>
    <input v-model="email" type="email" placeholder="Email" />
    <input v-model="password" type="password" placeholder="Password" />
    <button @click="handleLogin">登录</button>
  </div>
</template>

<script>
import { login } from '../api';

export default {
  data() {
    return {
      email: '',
      password: '',
    };
  },
  methods: {
    async handleLogin() {
      try {
        const res = await login({ email: this.email, password: this.password });
        if (res.data.success) {
          localStorage.setItem('email', this.email);
          this.$router.push('/dashboard');
        }
      } catch (error) {
        alert('登录失败');
      }
    },
  },
};
</script>

<style scoped>
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
input {
  margin: 10px;
  padding: 8px;
}
button {
  padding: 10px 20px;
}
</style>
